package edu.gyc.stu.controller;

import edu.gyc.stu.dao.UserDao;
import edu.gyc.stu.model.User;
import edu.gyc.stu.util.Info;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.logging.Logger;

@WebServlet(name = "RegServlet",urlPatterns = {"/reg"})
public class RegServlet extends HttpServlet {
    private static Logger logger = Logger.getLogger("RegServlet");

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        User user=new User();
        try {
            BeanUtils.populate(user, request.getParameterMap());
        } catch (Exception e) {
            e.printStackTrace();
        }
        UserDao userDao=new UserDao();
        Info info = userDao.addUser(user);
        request.setAttribute("info",info);
        request.getRequestDispatcher("reg.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
